package cn.hchaojie.snippets.temp;

import java.io.IOException;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.ListActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.ArrayAdapter;
import cn.hchaojie.snippets.AssetHelper;

public class TempActivity extends ListActivity {
	public static final String TAG = "Temp Activity";
    @Override
    public void onCreate(Bundle savedInstanceState) {
    	super.onCreate(savedInstanceState);
    	
    	String[] contents = null;
    	try {
			JSONObject root = AssetHelper.readJson(this, "data/all_activities.json");
			
			JSONArray activities = root.getJSONArray("activities");
			contents = new String[activities.length()];
			for (int i = 0; i < activities.length(); i++) {
				JSONObject object = activities.optJSONObject(i);
				if (object != null) {
					contents[i] = object.optString("content");
				}
			}
		} catch (IOException e) {
			Log.e(TAG, "Get asset data/all_activities.json error. " + e.getMessage());
		} catch (JSONException e) {
			Log.e(TAG, "Parse json data error: " + e.getMessage());
		}
    	
    	setListAdapter(new ArrayAdapter<String>(this,
              android.R.layout.simple_list_item_1, contents));
    }
}
